<?php
namespace fast;
	date_default_timezone_set('PRC');
	class request{

		//获取access_token
		public function getAccessToken($appId, $appSecret){
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appId&secret=$appSecret";

			//访问数据接口
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);

            $jsoninfo = json_decode($output, true);
//             var_dump($jsoninfo);exit;
			$access_token = $jsoninfo["access_token"];

			return $access_token;
		}

		//执行get请求
		public function wx_get($url){

			//访问数据接口
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL, $url);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			$output = curl_exec($ch);
			curl_close($ch);

			//数据转换成数组格式
			$jsoninfo = json_decode($output, true);

			return $jsoninfo;
		}

		//执行post请求
		public function wx_post($url,$data){

			//将post的数据转换为json格式
			$post_data=json_encode($data,JSON_UNESCAPED_UNICODE);
			$chr = curl_init();
            curl_setopt ($chr, CURLOPT_URL, $url );
            curl_setopt ($chr, CURLOPT_SSL_VERIFYPEER, FALSE );
            curl_setopt ($chr, CURLOPT_SSL_VERIFYHOST, FALSE );
            curl_setopt($chr, CURLOPT_HEADER, 0);//设置header
            curl_setopt($chr, CURLOPT_POST, true);  
            curl_setopt($chr, CURLOPT_POSTFIELDS, $post_data);  
            curl_setopt($chr, CURLOPT_RETURNTRANSFER, true);   
            $output = curl_exec($chr);

			if($error=curl_error($chr)) {
                die($error);  
            }  
			curl_close($chr);
			//数据转换成数组格式
			$jsoninfo = json_decode($output, true);

			return $jsoninfo;
			}

	}
?>